<?php
    include "../mysql/mysql.php";
    $aa = new mysql;
    $aa->link("");
    include "../myfunction.php";
    $bb= new myfunction;
	
$r2proid = @isset($_POST["r2proid"]) ?  @$_POST["r2proid"] : ''; // var_dump($r2proid); //id user for edit
$r2proname = @isset($_POST["r2proname"]) ?  @$_POST["r2proname"] : '';  //var_dump($r2proname);

$r2class = @isset($_POST["r2class"]) ?  @$_POST["r2class"] : '';  // var_dump($r2class); //classid

$r2intro = @isset($_POST["r2intro"]) ?  @$_POST["r2intro"] : '';  // var_dump($r2intro);
$r2price = @isset($_POST["r2price"]) ?  @$_POST["r2price"] : '';  // var_dump($r2price);
$r2showorder = @isset($_POST["r2showorder"]) ?  @$_POST["r2showorder"] : 0;   //var_dump($r2showorder);

$r2hot = @isset($_POST["r2hot"]) ?  1 : 0;  // var_dump($r2hot); //hot?


$r2col = '颜色#';  
$check = @isset($_POST['check']) ?  @$_POST['check'] : '';    // var_dump($check);
if($check != ''){
foreach($check as $i){ $r2col.=$i."^"; }	}
   var_dump($r2col);


$r2ex02 = @isset($_POST["r2ex02"]) ?  @$_POST["r2ex02"] : '';   // var_dump($r2ex02);

$r2tech = @isset($_POST["r2tech"]) ?  @$_POST["r2tech"] : '';    //var_dump($r2tech);

//img
$pronum = @isset($_POST["imgpronum"]) ?  @$_POST["imgpronum"] : '';
$proinfonum = @isset($_POST["imgproinfonum"]) ?  @$_POST["imgproinfonum"] : '';
$file = @isset( $_FILES) ? @$_FILES : '';
$imgsrc=$detinfo='';
//var_dump($_FILES);  var_dump($file);

if(!file_exists("upload")){
               // 如果没有  目录，创建upload 目录权限默认为 777                
               mkdir("upload"); 
	         //  echo "当前目录中，文件img不存在.已为您创建". "<br>";
              }
for($i=0; $i < ($pronum+$proinfonum); $i++){
	if($i<$pronum){
		$ff1 = "filea".$i; 
		$filename = $file[$ff1]['name'];
		$filetmp = $file[$ff1]['tmp_name'];
		$bb->uploadpropic($filetmp, $filename);
		$imgsrc= $imgsrc."upload/".$filename."#"; 
		}
		else{
			$j=0; $ff2 = "fileb".$j;
			$filename = $file[$ff2]['name'];
		    $filetmp = $file[$ff2]['tmp_name'];
			$bb->uploadpropic($filetmp, $filename);
		    $detinfo= $detinfo."upload/".$filename."#"; 
			$j++;
			}

	}

//echo $imgsrc."<br>"; echo $detinfo."<br>";

$aa = new mysql;
$aa->link("");
if($r2proid == ''){ //echo 1;
	$sql= "INSERT INTO product_info (class_id, name, intro, imgsrc, show_order, price, hot, det_info, tech, ex01, ex02) 
                       VALUES ($r2class, '$r2proname', '$r2intro', '$imgsrc', $r2showorder, $r2price, $r2hot, '$detinfo', '$r2tech', '$r2col', '$r2ex02') ";
	}
	else{// echo 2;
		$sql = "UPDATE product_info SET class_id= '".$r2class."' name= '".$r2proname."'  intro= '".$r2intro."' imgsrc= '".$imgsrc."'  show_order= '".$r2showorder."'
		 price= '".$r2price."' hot= '".$r2hot."' det_info= '".$detinfo."' tech= '".$r2tech."' ex01= '".$r2col."'
		  ex02= '".$r2ex02."'  WHERE id='".$r2proid."' ";  // 如何一次更新过个数据？ 
		}

       $result= $aa->excu($sql);

if ($result == TRUE) {
	$query= "select * from product_info where name = '".$r2proname."' ";
		$res= $aa->excu($query);
		$res = mysqli_fetch_array($res);
	?>
<div style=" top: 200px; left: 300px; padding: 20px;">恭喜您,添加商品成功！<a href="../productshow.php?id= <?php echo $res['id']; ?> "><span><strong>预览</strong></span></a></div>

<?php
} else {
  ?>
 <div style=" top: 200px; left: 300px; padding: 20px;"> 添加商品失败，请重新<a href="index.php?rnum=2">添加</a></div>
  <?php
}   
 ?>













?>